<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../application/vue.js"></script>
    <style>
        #app{
            background-color:#ccc;
            padding:10px;
        }
        .child{
            background-color:skyblue;
            padding:10px;
        }
    </style>
</head>
<body>
    <div id="app">
        <p>父组件</p>
        <!-- <p>msg:{{msg}}</p> -->
        <hr>
        <child-two></child-two>
        <hr>
        <child-one></child-one>
    </div>
    <template id="ChildOne">
        <div class="child">
            <p>子组件1</p>
            <p>msg:{{msg}}</p>
        </div>
    </template>
    <template id="ChildTwo">
        <div class="child">
            <p>子组件2</p>
            <p>msg:{{msg}}</p>
        </div>
    </template>
</body>
<script>
    new Vue({
        el:"#app",
        components:{
            childOne:{
                template:"#ChildOne",
                data(){
                    return{
                        msg:""
                    }
                },
                // mounted(){
                //     this.$root.$on("update:msg",(arg)=>{
                //         this.msg=arg;
                //     })
                // }
                beforeMount(){
                    this.$root.$on("update:msg",(arg)=>{
                        this.msg=arg;
                    })
                }
            },
            childTwo:{
                template:"#ChildTwo",
                data(){
                    return{
                        msg:"子组件2中的变量"
                    }
                },
                mounted(){
                    this.$root.$emit("update:msg",this.msg);
                }
            }
        }
    })
</script>
</html>